<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .select_grouptour dl{
            width: 600px;
        }
        .layui-form-label{
            width: 100px;
        }
        .layui-input-block{
            margin-left: 130px;
        }
    </style>
</head>
<body>
<div style="margin-top: 20px;">
</div>

<form class="layui-form" id="admin">
    <div class="layui-form-item">
        <label class="layui-form-label">群标题</label>
        <div class="layui-input-inline" style="width: 600px">
            <input name="title" lay-verify="required" value='{notempty name="$info.title"}{$info.title}{/notempty}{notempty name="$lineInfo.title"}{$lineInfo.title}{/notempty}' placeholder="请输入群标题" autocomplete="off" class="layui-input" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">群简介</label>
        <div class="layui-input-inline" style="width:600px;">
            <textarea placeholder="请输入群简介"  class="layui-textarea" name="desc">{notempty name="$info.desc"}{$info.desc}{/notempty}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">关联拼游产品</label>
        <div class="layui-input-inline select_grouptour" style="width:600px;">
            <select name="grouptour_id" id="" lay-verify="required" class="layui-select" lay-search="">
                <option value="">请选择拼游产品</option>
                {volist name='tourlist' id='value'}
                <option value="{$value.line_id}" {notempty name="info.grouptour_id"}{if $info.grouptour_id==$value.line_id}selected{/if}{/notempty}{notempty name="lineInfo.line_id"}{if $lineInfo.line_id==$value.line_id}selected{/if}{/notempty}>{$value.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">过期提醒邮箱</label>
        <div class="layui-input-inline" style="width: 600px">
            <input name="notice_email" lay-verify="required" {notempty name="$info.notice_email"}value="{$info.notice_email}"{/notempty} placeholder="请输入过期提醒邮箱，多邮件使用英文','分隔，eg:123@qq.com,456@qq.com" autocomplete="off" class="layui-input" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">过期时间</label>
        <div class="layui-input-inline" style="width: 300px">
            <input name="expire_time" lay-verify="required" {notempty name="$info.expire_time"}value="{$info.expire_time}"{/notempty} placeholder="请输入过期时间，eg:2020-01-01" autocomplete="off" class="layui-input x" type="text">
        </div>
    </div>
    <div class="layui-upload" id="upload-thumb">
        <label class="layui-form-label">群二维码</label>
        <button type="button" class="layui-btn" id="thumb">上传群二维码</button>
        <div class="layui-upload-list">
            <label class="layui-form-label"></label>
            <img class="layui-upload-img" id="demo1" width="150" height="150" {notempty name='$info.qrcode'}src="{$info.qrcode|geturl}"{/notempty}>
            <p id="demoText"></p>
        </div>
    </div>
    <input type="hidden" name="qrcode" value="{notempty name='info.qrcode'}{$info.qrcode}{/notempty}">
    {notempty name="$info"}
    <input type="hidden" name="id" value="{$info.id}">
    {/notempty}

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message','laydate'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer,
            laydate = layui.laydate;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();

        //批量初始化时间控件
        $('.x').each(function() {
            laydate.render({
                elem: this, //指定元素
                trigger:'click',
            });
        });

    });
</script>

<script>
    layui.use(['layer', 'form'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;
        $(window).on('load', function() {
            form.on('submit(admin)', function(data) {
                //检查图片是否上传
                if($('input[name=qrcode]').val()==''){
                    layer.msg('请上传群二维码图片!');
                    return false;
                }
                $.ajax({
                    url:"{:url('admin/grouptoursline/addqrcode')}",
                    data:$('#admin').serialize(),
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            },1500)
                        }
                    }
                })
                return false;
            });
        });
    });
</script>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#thumb' //绑定元素
            ,url: "{:url('common/upload')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    $('#demo1').attr('src',res.src);
                    $("input[name=qrcode]").val(res.id);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                //演示失败状态，并实现重传
                layer.closeAll('loading');
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function () {
                layer.load(2);
            }
        });
    });
</script>
<script>
    $("#demo1").click(function(){
        var that = this;
        amplificationImg(that);
    })

    function amplificationImg(that) {
        var url = $(that).attr("src");
        if(url=="" || url==undefined){
            return false;
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shadeClose: true,
            area: ['400px', '600px'], //宽高
            content: "<img width='400' src=" + url + " />"
        });
    }
</script>
</body>
</html>
